package pers.xiaojun.boot.tenant.core.context;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * 多住户上下文
 *
 * @author xiaojun
 * @since 2025-11-21
 */
public class TenantContextHolder {

    /**
     * 当前租户套餐Id
     */
    private static final ThreadLocal<Long> TENANT_ID = new TransmittableThreadLocal<>();

    /**
     * 设置当前租户套餐Id
     *
     * @param tenantId 租户套餐Id
     */
    public static void setTenantId(Long tenantId) {
        TENANT_ID.set(tenantId);
    }

    /**
     * 获取当前租户套餐Id
     *
     * @return 租户套餐Id
     */
    public static Long getTenantId() {
        return TENANT_ID.get();
    }

    /**
     * 清除租户
     */
    public static void clear() {
        TENANT_ID.remove();
    }

}
